package dynamicmenus;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.form.Form;

import cruds.accessories.AccessoryList;
import cruds.accessories.CrudCreateAccessory;
import home.Home;
import panels.DynamicMenu;
import panels.MyAjaxLink;
import services.StockableService;

@SuppressWarnings("serial")
public class AccessoriesMenu extends DynamicMenu{

	public AccessoriesMenu(Home home) {
		super(home);
		this.setOutputMarkupId(true);
		this.createLinks();
	}

	private void createLinks() {
		StockableService service = this.getHome().getGeneralService().getStockableSer();
		this.createCreateAccessoryButton();
	    this.add(new MyAjaxLink("bulones",new AccessoryList(this.getHome(), service.searchAccessories("Bulon"))));
	    this.add(new MyAjaxLink("cubrebulones",new AccessoryList(this.getHome(), service.searchAccessories("Cubre Bulon"))));
	    this.add(new MyAjaxLink("graceras",new AccessoryList(this.getHome(), service.searchAccessories("Gracera"))));
	    this.add(new MyAjaxLink("clliso",new AccessoryList(this.getHome(), service.searchAccessories("Centro Llanta Liso"))));
	    this.add(new MyAjaxLink("cllogo",new AccessoryList(this.getHome(), service.searchAccessories("Centro Llanta Logo"))));
	    this.add(new MyAjaxLink("tasitas",new AccessoryList(this.getHome(), service.searchAccessories("Tasita Plastica"))));
	    this.add(new MyAjaxLink("separadores",new AccessoryList(this.getHome(), service.searchAccessories("Separador"))));
	    this.add(new MyAjaxLink("logos",new AccessoryList(this.getHome(), service.searchAccessories("Logo"))));
	    this.add(new MyAjaxLink("camaras",new AccessoryList(this.getHome(), service.searchAccessories("Camara"))));
	}

	private void createCreateAccessoryButton() {
		Form form = new Form("form");
        this.add(form);
        form.add(new AjaxButton("crear") {

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				CrudCreateAccessory page = new CrudCreateAccessory(AccessoriesMenu.this.getHome());
				page.changePanel(target);
			}

			@Override
			protected void onError(AjaxRequestTarget target, Form<?> form) {
				
			}
        });
	}

}
